package com.bootdo.system.controller;

import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;
import com.bootdo.system.domain.TaTestDO;
import com.bootdo.system.service.TaTestService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 
 * 
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2018-10-31 15:24:19
 */
 
@Controller
@RequestMapping("/system/taTest")
public class TaTestController {
	@Autowired
	private TaTestService taTestService;
	
	@GetMapping()
	@RequiresPermissions("system:taTest:taTest")
	String TaTest(){
	    return "system/taTest/taTest";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("system:taTest:taTest")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<TaTestDO> taTestList = taTestService.list(query);
		int total = taTestService.count(query);
		PageUtils pageUtils = new PageUtils(taTestList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("system:taTest:add")
	String add(){
	    return "system/taTest/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("system:taTest:edit")
	String edit(@PathVariable("id") Long id,Model model){
		TaTestDO taTest = taTestService.get(id);
		model.addAttribute("taTest", taTest);
	    return "system/taTest/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("system:taTest:add")
	public R save( TaTestDO taTest){
		if(taTestService.save(taTest)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("system:taTest:edit")
	public R update( TaTestDO taTest){
		taTestService.update(taTest);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("system:taTest:remove")
	public R remove( Long id){
		if(taTestService.remove(id)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("system:taTest:batchRemove")
	public R remove(@RequestParam("ids[]") Long[] ids){
		taTestService.batchRemove(ids);
		return R.ok();
	}
	
}
